<template>
  <router-view />
</template>

<script>
export default {
  name: 'app',
  data() {
    return {}
  },
  computed: {
    browser() {
      return this.$store.state.browser;
    }
  },
  methods: {
    ready() {
      this.loadData();
      this.reactiveScreenWidth();
    },

    /**加载数据 */
    loadData() {
      this.loadGameData();
    },

    /**标签数据 */
    loadTagsData() {
      return new Promise((resolve, reject) => {
        this.dgpost(this.api.GETTAGSDATA, {})
        .then(res => {
          this.$store.commit('setTags', res.data.data || []);
          resolve();
        }).catch(err => {
          this.$message({
            title: '加载标签数据发生错误',
            type: 'error',
            message: err.msg,
            closeable: true
          });
          reject();
        });
      });
    },

    /**单一状态响应式屏幕宽度 */
    reactiveScreenWidth() {
      let timer = false;
      window.onresize = () => {
        if(!timer) {
          timer = true;// 禁用
          setTimeout(() => {
            this.$store.commit('resizeScreen', document.body.clientWidth);
            timer = false;
          }, 599);// 性能优化处理
        }
      }
    }
  },
  watch: {
    /**顶部菜单选中匹配 */
    $route(to, from) {
      const pipei = {
        'HomeWorksList': 0,
        'Game': 1,
        'DesignerList': 2,
        'PrizeList': 3,
        'ExcellentCase': 4
      }
      this.$store.commit('setCurIndex', pipei[to.name]);
    }  
  },
  mounted() {
    document.oncontextmenu = () => {
      if(window.event.srcElement.tagName === "IMG") {
        // alert("对不起,您不能保存此图片,谢谢您的理解和支持!");
        window.event.returnValue = false;
      }
    }
    this.ready();
  }
}
</script>